package com.example.note.model;

import com.example.note.common.Constants;
import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 */
@Data
public class Result<T> {
    /**
     * 自定义状态码：200 - 成功
     *             -1 - 失败
     */
    private int code;
    private String errorMsg;
    /**
     *  这里是真正需要的结果，其它两个为修饰内容
     */
    private T data;

    //创建一些方法
    public  static <T> Result <T> success(T data){
        Result result = new Result();
        result.setCode(Constants.RESULT_SUCCESS);
        result.setData(data);
        result.setErrorMsg("");
        return result;
    }

    public  static <T> Result <T> fail(String errorMsg){
        Result result = new Result();
        result.setCode(Constants.RESULT_FAIL);
        //result.setData(data);
        result.setErrorMsg(errorMsg);
        return result;
    }

    public  static <T> Result <T> fail(String errorMsg,T data){
        Result result = new Result();
        result.setCode(Constants.RESULT_FAIL);
        result.setData(data);
        result.setErrorMsg(errorMsg);
        return result;
    }

}
